from PyQt5.QtWidgets import (
    QApplication,
    QWidget,
    QLabel,
    QLineEdit,
    QPushButton,
    QVBoxLayout,
    QHBoxLayout,
    QGridLayout,
)
import sys
from PyQt5.QtWidgets import QFormLayout


class myWindow(QWidget):
    def __init__(self):
        super().__init__()

        screen_geometry = QApplication.desktop().screenGeometry()
        screen_width = screen_geometry.width()
        screen_height = screen_geometry.height()
        # Example: Center the window
        self.width = 800
        self.height = 540
        # self.setFixedSize(self.width, self.height)
        self.left = (screen_width - self.width) // 2
        self.top = (screen_height - self.height) // 2
        self.setGeometry(self.left, self.top, self.width, self.height)
        self.label1 = QLabel("I am Label1")
        self.button1 = QPushButton("#button1")
        self.button2 = QPushButton("#button2")
        self.button3 = QPushButton("#button3")
        self.button4 = QPushButton("#button4")
        self.initUI()

    def initUI(self):
        self.label1.resize(200, 50)
        # self.label1.setGeometry(10, 10, 100, 50)
        # self.button1.setGeometry(10, 60, 100, 50)
        # self.button2.setGeometry(10, 110, 100, 50)
        # self.button3.setGeometry(10, 160, 100, 50)
        self.button1.setObjectName("button1")
        self.button2.setObjectName("button2")

        # self.button2.setStyleSheet(
        #     "background-color:  #FF0000;border: 1px solid #000000;border-radius: 10px;"
        # )
        self.button3.setStyleSheet(
            "background-color:  #0099FF;border: 1px solid #000000;border-radius: 10px"
        )
        self.button4.setStyleSheet(
            "background-color:  #0199EF;border: 1px solid #000000;border-radius: 10px"
        )
        layout = QGridLayout()
        layout.addWidget(
            self.button1, 0, 0, 1, 2
        )  # 0,0 表示第0行第0列，1,2 表示占1行2列
        layout.addWidget(self.button2, 0, 2)  # 1,0 表示第1行第0列
        layout.addWidget(self.button3, 1, 0)  # 1,0 表示第1行第0列
        layout.addWidget(self.button4, 1, 1)  # 1,1 表示第1行第1列
        # layout.addWidget(self.button1)
        # layout.addWidget(self.button2)
        # layout.addWidget(self.button3)
        self.setLayout(layout)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setStyle("Fusion")
    window = myWindow()
    with open("style.css", "r") as f:
        app.setStyleSheet(f.read())
    window.show()
    sys.exit(app.exec_())
